//
//  UpdateTableViewCell.m
//  Cartoon
//
//  Created by dllo on 15/10/29.
//  Copyright © 2015年 YSZ. All rights reserved.
//

#import "UpdateTableViewCell.h"
#import "UpdateModel.h"
@implementation UpdateTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _cover_urlImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_cover_urlImageView];
        
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor colorWithRed:13 / 255.0 green:184 / 255.0 blue: 240 / 255.0 alpha:1];
        [self.contentView addSubview:_titleLabel];
        
        _artist_nameLabel = [[UILabel alloc] init];
        _artist_nameLabel.textColor = [UIColor lightGrayColor];
        _artist_nameLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_artist_nameLabel];
        
        _lated_seqnoLabel = [[UILabel alloc] init];
        _lated_seqnoLabel.textColor = [UIColor lightGrayColor];
        _lated_seqnoLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_lated_seqnoLabel];
        
        _starView = [[StarView alloc] init];
        [self.contentView addSubview:_starView];
        
        _grade_aveLabel = [[UILabel alloc] init];
        _grade_aveLabel.textColor = [UIColor lightGrayColor];
        _grade_aveLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_grade_aveLabel];
    }

    return self;

}

+ (instancetype)updateCellWithTableView:(UITableView *)tableView
{

    UpdateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    return cell;
}

//自定义分割线
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextFillRect(context, rect);
    
    //下分割线
    CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:52/225. green:143/225. blue:110/225. alpha:1.].CGColor);
    CGContextStrokeRect(context, CGRectMake(100, rect.size.height, rect.size.width - 20, 1));
}


- (void)setUpdateModel:(UpdateModel *)updateModel
{
    _updateModel = updateModel;
    [_cover_urlImageView sd_setImageWithURL:[NSURL URLWithString:updateModel.cover_url]placeholderImage:[UIImage imageNamed:@"5"]];
    _titleLabel.text = updateModel.title;
    _artist_nameLabel.text = [NSString stringWithFormat:@"作者: %@",updateModel.artist_name];
    _lated_seqnoLabel.text = [NSString stringWithFormat:@"更新至%@话",updateModel.lated_seqno];
    self.starView.starNum = [updateModel.grade integerValue];
    self.grade_aveLabel.text = [NSString stringWithFormat:@"评分: %@",updateModel.grade_ave];

}


- (void)layoutSubviews
{
    [super layoutSubviews];

    _cover_urlImageView.frame = CGRectMake(5, 5, 80, 100);
    _titleLabel.frame = CGRectMake(100, 10, 200, 20);
    _artist_nameLabel.frame = CGRectMake(100, 35, 200, 20);
    _lated_seqnoLabel.frame = CGRectMake(100, 60, 200, 20);
    _starView.frame = CGRectMake(100, 85, 100, 20);
    _grade_aveLabel.frame = CGRectMake(220, 85, 80, 20);
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
